<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<link rel="stylesheet" type="text/css" href="<%=path%>/css/easyui.css">
<link rel="stylesheet" type="text/css" href="<%=path%>/css/icon.css">
<link rel="stylesheet" type="text/css" href="<%=path%>/css/demo.css">
<link rel="stylesheet" href="<%=path%>/css/bootstrap.min.css" />
<link rel="stylesheet" href="<%=path%>/css/easyui.css" />
<script type="text/javascript" src="<%=path%>/js/js_add/jquery-1.8.3.js"></script>
<script type="text/javascript" src="<%=path%>/js/js_add/jquery-ui.js"></script>
<script type="text/javascript"
	src="<%=path%>/js/js_add/jquery.ui.tabs.js"></script>
<script type="text/javascript" src="<%=path%>/js/jquery.easyui.min.js"></script>

<script type="text/javascript">

/* 日期格式化 */
var format = function(time, format){
    var t = new Date(time);
    var tf = function(i){return (i < 10 ? '0' : '') + i};
    return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a){
        switch(a){
            case 'yyyy':
                return tf(t.getFullYear());
                break;
            case 'MM':
                return tf(t.getMonth() + 1);
                break;
            case 'mm':
                return tf(t.getMinutes());
                break;
            case 'dd':
                return tf(t.getDate());
                break;
            case 'HH':
                return tf(t.getHours());
                break;
            case 'ss':
                return tf(t.getSeconds());
                break;
        }
    })
}


	$(function() {
		$("#dg").datagrid({
			url : '<%=path%>/news/getAllNews',
			singleSelect: true,//单选效果
			//iconCls: 'icon-search',
			rownumbers : true,
			pagination : true,//显示底部分页栏
			pageSize : 4,//默认每页记录数
			pageList : [ 2, 4, 6 ],
			fitColumns : true,//自适应宽度，防止水平滚动
			striped : true,//隔行变色
			
			toolbar:[{  
            text: '添加',  
            iconCls: 'icon-add',  
            handler: function() {
                $('#dlg').dialog('open').window('center');
            
               
            }  
        }, '-', {  
            text: '修改',  
            iconCls: 'icon-edit',  
            handler: function() {  
                //alert("修改");  
                var row=$("#dg").datagrid("getSelected");
                //alert(row.nid);
                window.location.href='toUpdateNews?NId='+row.nid;
                $('#dlg2').dialog('open').window('center');      
            }  
        }, '-',{  
            text: '删除',  
            iconCls: 'icon-remove',  
            handler: function(){  
              var row=$("#dg").datagrid("getSelected");
               //alert(depts.nid);
               //删除后返回到当前页
               $.messager.confirm("删除框","确定删除？",function(abc){
	                if(abc){
	                             		
	                  window.location.href='<%=path%>/news/delNews?NId='+row.nid;
	                   
	                }	                 
	           });         	
            }  
        }],columns : [ [ {field : 'ck',checkbox : true}, 
        {field : 'nid',	title : '编号',width : 10}, 
        {field : 'ntitle',title : '公告标题',align : 'center',width : 40},
        {field : 'ntext',title : '内容',align : 'center',width : 100},
        {field : 'ntime',title : '时间',align : 'center',width : 40 ,
        formatter: function (value,row,index) {
			return format(value,'yyyy-MM-dd');
		}},
        {field : 'nstate',	title : '状态' ,width : 10,
         formatter:function(value){
        if(value==1)
                return '已发布';
        else
                return '未发布';
        }
        }, 
        
        {field : 'def',title : '操作',align : 'center',width : 40,
                formatter:function(value,rec){ 
                var btn = '<a id="bbt" class="editcls" style="color:#008080" onclick="javascript:look('+rec.nid+');">详情</a>';  
                return btn;	}} ]],
			loadMsg : "正努力为您加载中......"
		});

	});
</script>


</head>

<body>
    
    <div id="dlg" class="easyui-dialog" title="Toolbar and Buttons"
		style="width:600px;height:400px;padding:20px"
		data-options="closed:true">
		亲,您可以进行添加了
		<form action="<%=path%>/news/addNews">
			    <input name="NId"  type="hidden" /><br> 
			       类型:<input name="TId"/><br> 
				标题:<input name="NTitle"/><br> 
				内容:<input name="NText" /><br> 
				发布时间:<input name="NTime"/><br> 
				状态:<select name="NState">
				<option value="0">未发布</option>
				<option value="1">已发布</option>
			    </select> 
			<input type="submit" /> <input type="reset" />
		</form>
	</div>
    

	<div id="dlg2" class="easyui-dialog" title="Toolbar and Buttons"
		style="width:600px;height:400px;padding:20px"
		data-options="closed:false">
		亲,您可以进行修改了
		<form action="<%=path%>/news/updateNews">
		        <input name="NId" value="${news.NId }"  type="hidden"/><br> 
			      类型:<input
				name="TId" value="${news.type.TId}" /><br> 标题:<input name="NTitle"
				value="${news.NId }" /><br> 内容:<input name="NText"
				value="${news.NText }" /><br> 发布时间:<input name="NTime"
				value="${news.NTime }" /><br> 状态:
				<c:if test="${news.NState==0 }">
				<select  name="NState">
				<option value="0">未发布</option>
				<option value="1">已发布</option>
			    </select> </c:if>
			    <c:if test="${news.NState==1 }">
				<select  name="NState">
				<option value="1">已发布</option>
				<option value="0">未发布</option>
			    </select> </c:if>
			    <input type="submit" /> <input type="reset" />
		</form>
	</div>
	
	<div id="grid">
		<table id="dg" title="公告管理列表">
		</table>
	</div>

</body>
</html>
